home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_1
/
count.bit
< prev
next >
Wrap
Text File
|
1995-03-23
|
1KB
|
32 lines
Article 4686 of comp.sys.handhelds:
Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!news.cs.indiana.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!wuarchive!uunet!mcsun!hp4nl!charon!jurjen
From: jurjen@cwi.nl (Jurjen NE Bos)
Newsgroups: comp.sys.handhelds
Subject: HP28/48: Hamming weight of binary number (BITS)
Message-ID: <3053@charon.cwi.nl>
Date: 1 Mar 91 13:28:04 GMT
Sender: news@cwi.nl
Organization: STORC, Veldhoven
Lines: 17
Originator: jurjen@lijster.cwi.nl
Everybody who has had a HP16 knows that it sometimes is very convenient to
compute the number of 1 bits in a number.
Computing this on a HP28 or HP48 seems to take some time. A recent discussion
in comp.arch yielded a much more efficient solution. I changed it a little
bit to make it work for 64 bits, and translated it into RPL. The program is
shown below.
Happy Hacking!
BITS:
\<< # 7777777777777777h OVER SR OVER AND
DUP2 SR AND ROT OVER SR AND + + -
DUP SR SR SR SR + #F0F0F0F0F0F0F0Fh AND
#FF DUP2 / * -
\>>
I leave proving that this works as an exercise to the reader :-)